package com.tea.source.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tea.source.dao.ProcessDao;
import com.tea.source.dao.SalesDao;
import com.tea.source.model.Process;
import com.tea.source.model.Sales;
import com.tea.source.util.SerialNumUtil;

@Component("salesService")
public class SalesService {
	private SalesDao salesDao;
	private ProcessDao processDao;
	
	public SalesDao getSalesDao() {
		return salesDao;
	}
	@Resource
	public void setSalesDao(SalesDao salesDao) {
		this.salesDao = salesDao;
	}

	public ProcessDao getProcessDao() {
		return processDao;
	}
	@Resource
	public void setProcessDao(ProcessDao processDao) {
		this.processDao = processDao;
	}


	public void add(Sales sales){
    	
    	Process p = this.processDao.loadById(sales.getJgid());
    	
    	sales.setXsserialnum(SerialNumUtil.XSserialnumFactory(p.getJgserialnum()));
    	
    	this.salesDao.save(sales);
    	
    }
	
	public Sales loadByXsid(String xsserialnum) {
		return this.salesDao.loadByXsid(xsserialnum);
	}
	
	public boolean isSalesExit(String xsserialnum){
		return this.salesDao.isSalesExit(xsserialnum);
	}
	
	
	
	
	

}
